# -*- coding: utf-8 -*-
#
# File: SIGFS.py
#
# Copyright (c) 2006 by IBICT
# Generator: ArchGenXML Version 1.5.0
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

__author__ = """IBICT <cadu@ibict.br>"""
__docformat__ = 'plaintext'


# Workflow Scripts for: sigfs_resolucao_workflow

##code-section workflow-script-header #fill in your manual code here
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_parent, aq_inner
##/code-section workflow-script-header


def checkPendingState(self, state_change, **kw):
    request = self.REQUEST
    context = state_change.object
    portal_catalog = getToolByName(context, 'portal_catalog')
    portal_workflow = getToolByName(context, 'portal_workflow')
    path = '/'.join(context.getPhysicalPath())
    objects = portal_catalog(path=path, portal_type=['Atividade'])

    for obj in objects:
        if obj.review_state != 'pending':
            raise 'Este estado não é aceito enquanto as atividades não estiverem todas pendentes'
            #raise TypeError('Este estado não é aceito enquanto as atividades não estiverem todas pendentes')


def checkPublishedState(self, state_change, **kw):
    request = self.REQUEST
    context = state_change.object
    ata = aq_parent(aq_inner(context))
    portal_catalog = getToolByName(context, 'portal_catalog')
    portal_workflow = getToolByName(context, 'portal_workflow')
    path = '/'.join(ata.getPhysicalPath())
    objects = portal_catalog(path=path, portal_type=['Ata'])

    for obj in objects:
        if obj.review_state != 'published':
            raise 'Este estado não é aceito enquanto as atas não estiverem todas publicadas'
            #raise TypeError('Este estado não é aceito enquanto as atas não estiverem todas publicadas')

